package com.qidian.buy.cms.controller;

import com.qidian.buy.cms.service.FileUploadService;
import com.qidian.buy.util.pojo.QdResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

/**
 * Author: 戴着假发的程序员
 * Date: 2024-05-09 10:24
 * company: 起点编程
 **/
@RestController
@RequestMapping("/wangUpload")
public class WangEditorUploadController {
    @Autowired
    private FileUploadService fileUploadService;
    @RequestMapping
    public Map uploadImage(@RequestParam("uploadFile") MultipartFile uploadFile) {
        Map map = new HashMap();
        try {
            QdResult qdResult = fileUploadService.uploadFile(uploadFile);
            map.put("errno",0);
            Map data = new HashMap();
            data.put("url",qdResult.getData());
            map.put("data",data);
        } catch (Exception e) {
            map.put("errno",1);
            map.put("message","图片上传失败");
        }
        return map;
    }
}
